package com.code.common.util;

import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 验证工具类
 *
 * @author tangyifei
 */
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public class ValidatorUtil {

    private static final int PHONE_LEN = 11;

    /**
     * 邮箱格式正则表达式
     */
    private static final String EMAIL_FORMAT = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    /**
     * 手机号码格式正则表达式
     */
    private static final String MOBILE_FORMAT = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";

    /**
     * 手机号码匹配模式
     */
    private static final Pattern MOBILE_PATTERN = Pattern.compile(MOBILE_FORMAT);

    /**
     * 邮箱匹配模式
     */
    private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_FORMAT);

    /**
     * 判断是否为邮箱
     *
     * @param email 邮箱
     * @return 邮箱验证与否
     */
    public static boolean isEmail(String email) {
        if (StringUtils.isEmpty(email)) {
            return false;
        }
        Matcher m = EMAIL_PATTERN.matcher(email);
        return m.matches();
    }

//	public static void main(String[] args) {
//			System.out.println(isMobile("08085897889"));
////			System.out.println(isMobile("1891234123"));
//	}
}
